﻿using System;
using LifeInSharePoint.Common;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace LifeInSharePoint.Blog.Layouts.LifeInSharePoint.Blog.admin
{
    public partial class @default : LayoutsPageBase
    {


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //Load Blog Settings
                TxtTwitter.Text = SPPropertyBagHelper.GetPropertyValue(SPContext.Current.Site.RootWeb, "BlogTwitterUrl");
                TxtFacebook.Text = SPPropertyBagHelper.GetPropertyValue(SPContext.Current.Site.RootWeb, "BlogFacebookUrl");
                TxtLinkedIn.Text = SPPropertyBagHelper.GetPropertyValue(SPContext.Current.Site.RootWeb, "BlogLinkedInUrl");
                TxtRss.Text = SPPropertyBagHelper.GetPropertyValue(SPContext.Current.Site.RootWeb, "BlogRSSUrl");

                // Save RSS Settings
                TxtFeedTitle.Text = SPPropertyBagHelper.GetPropertyValue(SPContext.Current.Site.RootWeb, "RSSFeedTitle");
                TxtFeedLink.Text = SPPropertyBagHelper.GetPropertyValue(SPContext.Current.Site.RootWeb, "RSSFeedLink");
                TxtFeedDescription.Text = SPPropertyBagHelper.GetPropertyValue(SPContext.Current.Site.RootWeb, "RSSFeedDescription");
                TxtFeedCopyright.Text = SPPropertyBagHelper.GetPropertyValue(SPContext.Current.Site.RootWeb, "RSSFeedCopyright");
            }
            BtnApply.Click += new EventHandler(BtnApply_Click);
        }

        void BtnApply_Click(object sender, EventArgs e)
        {
            // Save Blog Settings
            SPPropertyBagHelper.AddPropertyAndUpdate(SPContext.Current.Site.RootWeb, "BlogTwitterUrl", TxtTwitter.Text);
            SPPropertyBagHelper.AddPropertyAndUpdate(SPContext.Current.Site.RootWeb, "BlogFacebookUrl", TxtFacebook.Text);
            SPPropertyBagHelper.AddPropertyAndUpdate(SPContext.Current.Site.RootWeb, "BlogLinkedInUrl", TxtLinkedIn.Text);
            SPPropertyBagHelper.AddPropertyAndUpdate(SPContext.Current.Site.RootWeb, "BlogRSSUrl", TxtRss.Text);

            // Save RSS Settings
            SPPropertyBagHelper.AddPropertyAndUpdate(SPContext.Current.Site.RootWeb, "RSSFeedTitle", TxtFeedTitle.Text);
            SPPropertyBagHelper.AddPropertyAndUpdate(SPContext.Current.Site.RootWeb, "RSSFeedLink", TxtFeedLink.Text);
            SPPropertyBagHelper.AddPropertyAndUpdate(SPContext.Current.Site.RootWeb, "RSSFeedDescription", TxtFeedDescription.Text);
            SPPropertyBagHelper.AddPropertyAndUpdate(SPContext.Current.Site.RootWeb, "RSSFeedCopyright", TxtFeedCopyright.Text);
        }
    }
}
